package sh.grapendaal.tsuushin.module.uno.engine.dto.helper;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import sh.grapendaal.tsuushin.module.uno.engine.domain.Player;
import sh.grapendaal.tsuushin.module.uno.engine.dto.PlayerState;

public final class PlayerStateHelper {

	private PlayerStateHelper() {
		// Utility class
	}
	
	public static PlayerState createFromPlayer(Player player) {
		if (player == null) {
			return null;
		}
		PlayerState playerState = new PlayerState();
		playerState.setNickname(player.getNickname());
		playerState.setCards(Collections.unmodifiableList(player.getCards()));
		playerState.setNewCards(Collections.unmodifiableList(player.getNewCards()));
		playerState.setDrawnCard(player.getDrawnCard());
		playerState.setUnlockedAchievements(Collections.unmodifiableSet(player.getUnlockedAchievements()));
		playerState.setStatistics(StatisticsStateHelper.createFromStatistics(player.getStatistics()));
		return playerState;
	}
	
	public static List<PlayerState> createFromPlayer(List<Player> players) {
		List<PlayerState> result = new ArrayList<PlayerState>();
		for (Player player : players) {
			result.add(createFromPlayer(player));
		}
		return result;
	}
}
